package main

import (
	"OldPackageTest/go_mysql/sqlx/config"
	"OldPackageTest/go_mysql/sqlx/model"
	"fmt"
)

func main() {

}

func querySingleRow() {
	sqlStr := "select * from student where id =?"
	var u model.User
	if err := config.DB.Get(&u, sqlStr, 1); err != nil {
		fmt.Println("query error", err)
	}
	fmt.Println("id", u.Id, "name", u.Name)
}
func queryMultipleRow() []model.User {
	sqlStr := "select * from student"
	var u []model.User
	if err := config.DB.Select(&u, sqlStr, 1); err != nil {
		fmt.Println("query error", err)
	}
	return u
}

func selectNamedQuery() {
	sqlStr := "select * from student where age=:age"
	rows, _ := config.DB.NamedQuery(sqlStr, map[string]interface{}{
		"age": 22,
	})
	defer rows.Close()
	for rows.Next() {
		var u model.User
		if err := rows.StructScan(&u); err != nil {
			fmt.Println("struct failed error%v\n", err)
			continue
		}
		fmt.Println("%v", u)
	}
}
